<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="favicon.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>PWA Demo</title>
  </head>
  <body>
    <div id="app"></div>
    <script src="/js/main.js"></script>
    <script>
    //   navigator.serviceWorker.getRegistrations().then(function (regs) {
    //     for (let reg of regs) {
    //       console.log(reg,'----unregister')
    //       reg.unregister();
    //     }
    //   });

      navigator.serviceWorker
        // .register(`/sw.js?now=${Date.now()}`)
        .register(`/sw.js`)
        .then((reg) => console.log("SW registered!", reg))
        .catch((err) => console.log("Boo!", err));

        navigator.serviceWorker.addEventListener('message',function(e){
            console.log('--- get message',e.data)
            if(e.data==='sw.update'){
                window.location.reload()
            }
        })
      setTimeout(() => {
        const img = new Image();
        img.src = "/image/svg1.svg";
        document.body.appendChild(img);
      }, 3000);
    </script>
  </body>
</html>
